from django.http import JsonResponse, HttpResponse
from django.shortcuts import render, redirect
from django.views import View

from organization.models import OrganizationModel
from student.models import StudentModel
# from organization.models import OrganizationModel
# from appointment.models import AppointmentModel
from supervisor.models import AdminModel


# Create appointment views here.
def index(request):

    # 判断是否登录
    user_id = request.session.get('user_id')
    is_login = request.COOKIES.get('user_status')
    # 如果登录了就跳转到各自的主页
    if user_id and is_login:
        # 如果登录了就把用户的名字和id号找到
        if StudentModel.objects.filter(stu_num=user_id):
            return redirect(f'student:home')
        if AdminModel.objects.filter(tch_num=user_id):
            return redirect(f'supervisor:home')
        if OrganizationModel.objects.filter(email=user_id):
            return redirect(f'organization:home')

    return render(request, 'home_page/base_index.html')



